/*
 * BSM6.0
 *
 * Copyright 2012-2013 (C) SINODATA CO., LTD. All Rights Reserved.
 */
package com.sinodata.bsm.center.service.topo;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.sinodata.bsm.center.cache.TopuCatalogCache;
import com.sinodata.bsm.center.dao.impl.TopoCatalogDaoImpl;
import com.sinodata.bsm.common.vo.TopuCatalog;
import com.sinodata.bsm.common.vo.TopuConf;

/**
 * <p>
 * Description: 
 * </p>
 *
 * @author sunxiangxue
 * @version 1.0

 * <p>
 * History: 
 *
 * Date                     Author         Version     Description
 * ---------------------------------------------------------------------------------
 * 2012-6-12 下午3:32:06          sunxiangxue        1.0         To create
 * </p>
 *
 * @since 
 * @see     
 */
@Service
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public class TopoCatalogService {
    @Autowired
    private TopoCatalogDaoImpl topoCatalogDaoImpl;

    @Autowired
    private TopuCatalogCache topuCatalogCache;//缓存对象

    @Autowired
    private TopoService topoService;

    /**
     * @param topuCatalog
     * @throws Exception 
     */
    @Transactional(propagation = Propagation.REQUIRED)
    public void saveOrUpdate(TopuCatalog topuCatalog) throws Exception {
        topoCatalogDaoImpl.saveOrUpdate(topuCatalog);
    }

    /**
     * 查询所有拓扑分类。
     * @param topuCatalog
     * @return 拓扑分类信息集合
     */
    public List<TopuCatalog> findAll() {
        return topuCatalogCache.findAll();
    }

    /**
     * 通过ID查询拓扑分类信息
     * @param id
     * @return
     */
    public TopuCatalog findById(Long id) {
        return topuCatalogCache.get(id);
    }

    /**
     * 根据ID删除拓扑分类
     * @param id
     */
    @Transactional(propagation = Propagation.REQUIRED)
    public void delete(Long id) {
        /* 删除拓扑图信息及相应的首页播放记录 */
        List<TopuConf> list = topoService.findByCatalogId(id);
        for (TopuConf topuConf : list) {
            topoService.deleteByCatalogId(topuConf);
        }
        /* 删除拓扑目录信息*/
        TopuCatalog topuCatalog = topuCatalogCache.get(id);
        topoCatalogDaoImpl.delete(topuCatalog);
    }

}
